﻿using Panuon.UI.Silver;
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Effects;
using UIBrowser.Helpers;
using UIBrowser.Models;

namespace UIBrowser.PartialViews
{
    /// <summary>
    /// IconView.xaml 的交互逻辑
    /// </summary>
    public partial class IconUnicodeView : UserControl
    {
        public IconUnicodeView()
        {
            InitializeComponent();
            LoadFontItems();
            Loaded += ButtonView_Loaded;
        }
        private void ButtonView_Loaded(object sender, RoutedEventArgs e)
        {
            UpdateTemplate();
            UpdateCode();
        }

        #region FontItems
        public List<FontItem> MyFontItems { get => _fontItems; set => _fontItems = value; }
        private List<FontItem> _fontItems;
        #endregion

        #region SelectedFontItem
        public FontItem SelectedFontItem { get => _selectedFontItem; set => _selectedFontItem = value; }
        private FontItem _selectedFontItem;
        #endregion

        private void LoadFontItems()
        {
            MyFontItems = new List<FontItem>();
            //FontItems.Items
            //FontItems = new BindableCollection<FontItem>();
            long start = 0x2200; //Convert.ToInt32("F000", 16);
            for (int i = 0; i < 0xFF; i++)
            {
                var value = start + i;
                var icon = value.ToString("X4").ToLower();
                MyFontItems.Add(new FontItem() { Icon = (char)value, Code = icon });
            }
            start = 0x2500; //Convert.ToInt32("F000", 16);
            for (int i = 0; i < 0xFF; i++)
            {
                var value = start + i;
                var icon = value.ToString("X4").ToLower();
                MyFontItems.Add(new FontItem() { Icon = (char)value, Code = icon });
            }
            start = 0x2600;
            for (int i = 0; i < 0xFF; i++)
            {
                var value = start + i;
                var icon = value.ToString("X4").ToLower();
                MyFontItems.Add(new FontItem() { Icon = (char)value, Code = icon });
            }
            this.FontItems.ItemsSource = MyFontItems;
            //SelectedFontItem = FontItems.First();
        }

        private void LoadFontItems(int start,int end)
        {
            MyFontItems = new List<FontItem>();
            int len = end - start;
            for (int i = 0; i < len; i++)
            {
                var value = start + i;
                var icon = value.ToString("X4").ToLower();
                MyFontItems.Add(new FontItem() { Icon = (char)value, Code = icon });
            }
           
            this.FontItems.ItemsSource = MyFontItems;
        }
        private void UpdateTemplate()
        {
        }
        private void UpdateCode()
        {

        }

        private void btnPreviewFont_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string strStart = txtFrom.Text.Trim();
                string strEnd = txtTo.Text.Trim();
                int start = Convert.ToInt32(strStart, 16);
                int end = Convert.ToInt32(strEnd, 16);
                if (end > start)
                {
                    LoadFontItems(start, end);
                }

            }
            catch { }
        }
    }
}
